
import 'package:animation_effect_demo/src/widget/button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

import '../base/christmas_light_style.dart';

class ChristmasLightDialog extends StatelessWidget {
  final Widget? child;
  final Color? backgroundColor;
  final double? elevation;
  final EdgeInsets? insetPadding;
  final Clip clipBehavior;
  final ShapeBorder? shape;
  final AlignmentGeometry? alignment;
  final List<Widget>? actions;

  ChristmasLightDialog(
      {Key? key,
      this.backgroundColor,
      this.elevation,
      this.insetPadding = const EdgeInsets.all(20.0),
      this.clipBehavior = Clip.none,
      this.shape,
      this.alignment,
      this.child,
      this.actions});

  @override
  Widget build(BuildContext context) {
    Widget? actionsWidget;
    if (actions != null && actions!.isNotEmpty) {
      actionsWidget = Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20.0),
        child: Row(
          mainAxisAlignment: actions!.length > 1
              ? MainAxisAlignment.spaceAround
              : MainAxisAlignment.end,
          children: actions!,
        ),
      );
    }
    return Dialog(
      backgroundColor: backgroundColor,
      elevation: elevation,
      insetPadding: insetPadding,
      clipBehavior: clipBehavior,
      shape: shape,
      alignment: alignment,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          if (child != null)
            Container(
                constraints: BoxConstraints(minHeight: 100),
                alignment: Alignment.center,
                child: child!),
          if (actionsWidget != null) actionsWidget
        ],
      ),
    );
  }
}

class ChristmasLightNormalDialog extends StatelessWidget {
  final Widget? title;
  final VoidCallback? onCancel;
  final VoidCallback? onConfirm;
  final Widget child;
  final String? cancelText;
  final String? confirmText;

  ChristmasLightNormalDialog(
      {required this.child,
      this.title,
      this.onCancel,
      this.onConfirm,
      this.cancelText,
      this.confirmText});

  @override
  Widget build(BuildContext context) {
    return ChristmasLightDialog(
      child: Column(
        children: [
          if (title != null)
            Padding(
              padding: EdgeInsets.symmetric(vertical: 10.0),
              child: title,
            ),
          child,
        ],
      ),
      actions: [
        TextButton(
            onPressed: () => Navigator.of(context).pop(false),
            child: Text(
              cancelText != null ? cancelText! : '取消',
              style: TextStyle(color: Colors.grey),
            )),
        TextButton(
            onPressed: () => Navigator.of(context).pop(true),
            child: Text(confirmText != null ? confirmText! : '确定',
                style: TextStyle(color: christmasLightStyle.primaryColor))),
      ],
    );
  }
}

class ChristmasLightBottomSheet extends StatelessWidget {
  final Widget child;
  final double minHeight;
  final VoidCallback? onCancel;
  final VoidCallback? onConfirm;

  ChristmasLightBottomSheet(
      {required this.child,
      this.minHeight = 150,
      this.onCancel,
      this.onConfirm});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding:
          EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
      child: Container(
        width: double.infinity,
        constraints: BoxConstraints(minHeight: minHeight),
        padding: EdgeInsets.all(20.0),
        decoration: BoxDecoration(
            color: Theme.of(context).scaffoldBackgroundColor,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(10.0),
                topRight: Radius.circular(10.0))),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            child,
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 20.0),
              child: Row(
                children: [
                  Expanded(
                      child: ChristmasLightNegativeButton(
                    text: '取消',
                    onPressed: onCancel,
                  )),
                  SizedBox(
                    width: 10,
                  ),
                  Expanded(
                      child: ChristmasLightPositiveButton(
                    child: Text('确定'),
                    onPressed: onConfirm,
                  ))
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
